<?php

namespace App\Http\Controllers;

use App\Model\Rule;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public $rule=array();
    /**
     * Controller constructor.
     * @param $table_id
     */
    public function __construct($table_id = null)
    {
        $this->middleware(function ($request, $next)use($table_id) {
            #获取角色id
            $role_id = session('user.role_id');
            #获取授权信息
            $rule = Rule::access($role_id,$table_id);
            $this->rule['view'] = $rule['view'] ? $rule['view'] : 0;
            $this->rule['add'] = $rule['add'] ? $rule['add'] : 0;
            $this->rule['update'] = $rule['update'] ? $rule['update'] : 0;
            $this->rule['delete'] = $rule['delete'] ? $rule['delete'] : 0;
            return $next($request);
        });
    }
}
